package librarydemo;

/** 读者: 完成“核心类设计”要求（读者） */
public class Reader {
    private final String id;
    private final String name;
    private int maxLoans = 2; // 普通读者上限=2

    public Reader(String id, String name) {
        if (id == null || id.isBlank()) throw new IllegalArgumentException("读者号必填");
        if (name == null || name.isBlank()) throw new IllegalArgumentException("姓名必填");
        this.id = id.trim();
        this.name = name.trim();
    }

    public String getId() { return id; }
    public String getName() { return name; }
    public int getMaxLoans() { return maxLoans; }
    public void setMaxLoans(int maxLoans) {
        if (maxLoans <= 0) throw new IllegalArgumentException("maxLoans 必须 > 0");
        this.maxLoans = maxLoans;
    }

    @Override
    public String toString() {
        return String.format("Reader{id='%s', name='%s', maxLoans=%d}", id, name, maxLoans);
    }
}
